<?php

/**
 * 
 *
 * @version $Id: archiv.inc.php,v 1.12 2005/01/03 13:41:31 phppc Exp $
 * @copyright 2004 
 **/

$this->module_new_value["action"] = "archiv";
$archiv = $this->fun_sg2var("archiv");
$archiv = $this->uf_form_conf_def($archiv,array("normal","month","search"),"normal");
$search = $this->fun_sg2var("search");
if(isset($_GET["kat_id"])) $kat_id = $_GET["kat_id"];
else $kat_id = 0;

if(!isset($_GET["search_id"])) $_GET["search_id"] = 0;

if(!isset($_GET["page"])) $_GET["page"] = 1;

// Setting used variables
$where_content = "";
$month = "";
$year = "";
$last_month_link = "";
$last_month = 0;
$last_year = 0;
$month_input = "";
$year_input = "";
$next_month_link = "";
$next_month = 0;
$next_year = 0;
$hidden_fields = "";
$archiv_main = "";
$archiv_input = "";
$page_nav = "";

$kat_id = $this->uf_form_conf_def($kat_id,$this->kat_all_ids,0);

if ($archiv == "month") { // Month mode
    $month = $this->fun_sg2var("month");
	$year = $this->fun_sg2var("year");
	$month = $this->uf_form_conf_def($month,array(1,2,3,4,5,6,7,8,9,10,11,12),date("n",time()));
	$year_array = array();
	$year_start = 2000;
	$year_ende = 2010;
	for ($start = $year_start;$start <= $year_ende;$start++) {
		array_push($year_array,$start);
	}
	$year = $this->uf_form_conf_def($year,$year_array,date("Y",time()));
	if($month == 1) {
		$last_month = 12;
		$last_year = $year - 1;
	}else {
		$last_month = $month - 1;
		$last_year = $year;
	}
	if($month == 12) {
		$next_month = 1;
		$next_year = $year + 1;
	}else {
		$next_month = $month + 1;
		$next_year = $year;
	}
	$last_month_link = $this->fun_make_link("","archiv=month&month=$last_month&year=$last_year&kat_id=$kat_id");
	$next_month_link = $this->fun_make_link("","archiv=month&month=$next_month&year=$next_year&kat_id=$kat_id");
	$month_input = $this->uf_make_input_name(1,12,$month,"monat","month");
	$year_input = $this->uf_make_input($year_start,$year_ende,$year,"year");
	$hidden_array["archiv"] = "month";
	$start_month = gmmktime (0,0,0,$month,1,$year,0) - $this->db_config["time_zone"];
	$ende_month = gmmktime (23,59,59,$month + 1,0,$year,0)  - $this->db_config["time_zone"];
	$this->where_time .= " AND ".$this->config["prefix"]."main.time_start >= $start_month AND time_start < $ende_month ";
}elseif ($archiv == "search") {
	$search = $this->uf_form_conf_def($search,array("input","get","insert"),"input");
	$hidden_array["archiv"] = "search";
	$hidden_array["search"] = "insert";
    $this->uf_field[1] = "content";
		$this->uf_input[1]["size"] = 30;
		$this->uf_input[1]["ml"] = 255;
	$this->uf_field[2] = "kat_id";
		$this->uf_input[2]["type"] = "kat";
		$this->uf_input[2]["size"] = 1;
		$this->uf_input[2]["first_lang"] = "news_show_all_cats";
	$this->uf_field[3] = "n_title";
		$this->uf_input[3]["type"] = "yes_no";
	$this->uf_field[4] = "n_text";
		$this->uf_input[4]["type"] = "yes_no";
	$anzahl_inputs = count($this->uf_field);
	if ($search == "input") {
		$value_array["n_title"] = 1;
		$archiv_main = $this->uf_create_complete_form("archiv_search_title",$hidden_array,"archiv_search_submit","form_reset","complete_form","uf/","",$value_array,"archiv_search_"); 
	}elseif ($search == "get") {
		list($where_content,$kat_id) = $this->fun_search($_GET["search_id"]);
	}elseif ($search == "insert") {
		list($valid_array,$abfrage,$abfrage2) = $this->uf_create_array_conf("insert");
		$valid_input = $this->uf_form_conf($valid_array);
		if ($valid_input == 1) {
			$abfrage .= ",ip";
			$abfrage2 .= ",\"".$this->config["ip"]."\"";				
		    $this->db_abfrage_q("INSERT ".$this->config["prefix"]."search ($abfrage) VALUES ($abfrage2)");
			$search_id = $this->db_insert_id();
			list($where_content,$kat_id) = $this->fun_search($search_id);
			list($anzahl_news_search) = $this->fun_prepare_page_nav($this->where_time,$kat_id,$where_content);
			if ($anzahl_news_search >= 1) {
				$this->message_green[] = 120;
			    $this->w_leitung["number"] = 10;
				$this->w_leitung["url"] = $this->fun_make_link("","archiv=search&search=get&search_id=".$search_id."");
			}else {
				$this->message_red[] = 72;
				$this->w_leitung["number"] = 1;
			}
		}else {
			$this->message_red[] = 1;
			$this->w_leitung["number"] = 1;			
		}
	}
}
if ($search != "input" AND $search != "insert") {
    list($anzahl_news_aktuell,$where_kat,$button_kat_id) = $this->fun_prepare_page_nav($this->where_time,$kat_id,$where_content);
	list ($start,$page_nav) = $this->fun_nav_page_creator($anzahl_news_aktuell,$this->db_config["archiv_per_page"],$_GET["page"],5,1,"&archiv=$archiv&search=$search&search_id=".$_GET["search_id"]."&month=$month&year=$year",0,"page");
	$erg = $this->db_abfrage_q ($this->main_abfrage . $this->where_time. $where_kat . $where_content . "ORDER BY \"time_start\" DESC LIMIT $start,".$this->db_config["archiv_per_page"]."");
	if ($anzahl_news_aktuell >= 1) {
		$this->module_new_value["action"] = "com";
		$archiv_ones = "";
	    while($db_news = $this->db_abfrage_fetch($erg)){
			$news_link = $this->fun_make_link("","news_id=".$db_news["news_id"]."");
			list($db_news["n_title"]) = $this->fun_lim_news($db_news["n_title"],$this->db_config["archiv_length"],$this->db_config["lim_archiv"]);
			list ($start_date,$start_time) = $this->fun_tstamp2date($db_news["time_start"]);
			$this->tpl_load("news_archiv_one");
			$this->tpl_replace_vars(array("news_link" => $news_link,"news_title" => $db_news["n_title"],"start_date" => $start_date, "start_time" => $start_time));
			$archiv_ones .= $this->tpl_output();
		} // while
		$this->tpl_load("news_archiv_main");
		$this->tpl_replace_vars(array("archiv_ones" => $archiv_ones));
		$archiv_main = $this->tpl_output();
	}else $this->message_red[] = 71;
}
$this->kat_rek(0,"input",$kat_id,-1,1,"kat_id",1,"news_show_all_cats");
$input_kat = $this->kat_return_value();
$this->module_new_value["action"] = "archiv";
if(!isset($hidden_array)) $hidden_array = array("archiv" => "normal"); 
$hidden_fields = $this->uf_create_hidden_form($hidden_array);
if($archiv != "search") {
	$this->tpl_load("news_archiv_input");
	$this->tpl_replace_vars(array("archiv" => $archiv,"hidden_fields" => $hidden_fields,"input_kat" => $input_kat,"last_month_link" => $last_month_link,"last_month" => $last_month,"last_year" => $last_year,"month_input" => $month_input,"year_input" => $year_input,"next_month_link" => $next_month_link,"next_month" => $next_month,"next_year" => $next_year));
	$archiv_input = $this->tpl_output();
}
$link_array[1] = "normal";
$link_array[2] = "month";
$link_array[3] = "search";
$archiv_nav = $this->uf_link_nav_creator($archiv,"archiv_link_","archiv",$link_array,$this->fun_make_link("","nc_action=archiv"),"news_archiv_nav","news_archiv_nav_one");
$this->tpl_load("news_archiv");
$this->tpl_replace_vars(array("archiv_input" => $archiv_input, "archiv_main" => $archiv_main, "page_nav" => $page_nav,"archiv_nav" => $archiv_nav));
$nc_main = $this->tpl_output();

?>